using Catalog.Application.CatalogItems.Interfaces;
using Catalog.Domain.Entities;
using Microsoft.EntityFrameworkCore;

namespace Catalog.Infrastructure.Repositories;

public class CatalogItemRepository : ICatalogItemRepository
{
    private readonly CatalogDbContext _dbContext;

    public CatalogItemRepository(CatalogDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public async Task<CatalogItem?> GetByIdAsync(Guid id, CancellationToken cancellationToken)
    {
        return await _dbContext.CatalogItems
            .FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
    }



    public void Add(CatalogItem item)
    {
        _dbContext.CatalogItems.Add(item);
    }

    public void Remove(CatalogItem item)
    {
        _dbContext.CatalogItems.Remove(item);
    }
}
